package com.zw.controller.user;

import com.zw.core.domain.AjaxResult;
import com.zw.dto.ProjectDto;
import com.zw.entity.Project;
import com.zw.service.ProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Tag(name = "项目")
@RestController("userProjectController")
@RequestMapping("/user/project")
public class ProjectController {

    @Resource
    private ProjectService projectService;

    @Operation(summary = "查询项目列表")
    @GetMapping("/list")
    @PreAuthorize("@ss.authenticated()")
    public AjaxResult projectList(ProjectDto projectDto) {
        return AjaxResult.success(projectService.projectList(projectDto));
    }

    @Operation(summary = "查询项目")
    @GetMapping("/{id}")
    @PreAuthorize("@ss.authenticated()")
    public AjaxResult getProject(@PathVariable Long id) {
        return AjaxResult.success(projectService.getById(id));
    }

    @Operation(summary = "修改项目")
    @PutMapping
    @PreAuthorize("@ss.authenticated()")
    public AjaxResult updateProject(@RequestBody Project project) {
        projectService.updateById(project);
        return AjaxResult.success();
    }

    @Operation(summary = "删除项目")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ss.authenticated()")
    public AjaxResult deleteProject(@PathVariable Long id) {
        projectService.removeProjectById(id);
        return AjaxResult.success();
    }

    @Operation(summary = "新增项目")
    @PostMapping
    @PreAuthorize("@ss.authenticated()")
    public AjaxResult addProject(@RequestBody Project project) {
        projectService.save(project);
        return AjaxResult.success();
    }

}
